package examples
{
	import flash.display.StageQuality;
	import flash.display.BitmapData;
	import flash.events.Event;
	import flash.display.Sprite;
	import org.papervision3d.scenes.*;
	import org.papervision3d.objects.*;
	import org.papervision3d.cameras.Camera3D;
	import flash.display.StageScaleMode;
	import flash.display.Stage;
	import flash.events.MouseEvent;
	import org.papervision3d.core.proto.RenderCallback;
	import org.papervision3d.core.proto.MouseEventCallback;
	//import caurina.transitions.Tweener;
	
	
	
	public class SampleDemo extends Sprite
	{
		
		protected var scene : Scene3D;
		protected var camera : Camera3D;
		protected var rootNode : DisplayObject3D;
		protected var renderCallback : RenderCallback;
		protected var mec : MouseEventCallback;
		
		
		function SampleDemo() {
			//Tweener.init( stage );
			addEventListener( Event.ADDED_TO_STAGE, onAdded );
		}
		
		private function onAdded( e : Event ) : void {
			init();
			addChild( new FPS() );
			
		}
		
		protected function init():void
		{
			var s:Stage = stage; 
			s.quality = StageQuality.MEDIUM;
			s.scaleMode = StageScaleMode.NO_SCALE;
			s.quality = StageQuality.LOW;
			setupScene();
			
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
			stage.addEventListener(MouseEvent.MOUSE_WHEEL, onMouseWheel);
	
		}
		
		private function setupScene():void
		{
			var container : Sprite = new Sprite();
			
			addChild( container ) ;
			container.x = 500;
			container.y = 400;
			scene = new MovieScene3D( container );
			
	
			// Create camera
			camera = new Camera3D();
			camera.x = 0;
			camera.z = -900;
			camera.zoom = 10;
			camera.focus = 100;
			camera.sort = false;
			
			// test iso
			//camera.z = -1000000;
			//camera.zoom = 10000;
			
			// test fish eye
			//camera.z = -300;
			//camera.zoom = 2;
			
			renderCallback = new RenderCallback();
	
			//scene.initMouseEventCapture( camera );
			
			mec = new MouseEventCallback( scene, camera );
		}
		 
		
		private function onEnterFrame( e : Event ) : void {
			scene.renderCamera( camera, renderCallback );
		}
		
		
		private function onMouseWheel( e : MouseEvent ) : void {
			camera.zoom += e.delta / 10;
		}
	}
}